﻿package mortal.game.view.mount.newMountModuel
{
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.component.gconst.*;
    import mortal.game.manager.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.tooltip.tooltips.*;
    import mortal.game.view.skill.*;
    import mortal.game.view.skill.panel.render.*;

    public class OtherSkillItem extends SkillItem
    {
        private var _lockIcon:GImageBitmap;
        protected var _stateIcon:GImageBitmap;
        public var lockIconStyleName:String = "SkillLockIcon";
        private var _isLocking:Boolean;
        private var _hasLearnSkill:Boolean;
        private var _isShowUpgradeBtn:Boolean;
        protected var _colorBg:ScaleBitmap;
        protected var _isShowColorBg:Boolean = true;
        public var upgradeParam:Object;
        public var callBack:Function;
        public static const stateType_no:int = 0;
        public static const stateType_canLearn:int = 1;
        public static const stateType_canAdvance:int = 2;

        public function OtherSkillItem()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.mouseChildren = false;
            this.mouseEnabled = true;
            this.buttonMode = true;
            this.configEventListener(MouseEvent.CLICK, this.clickMeHandler);
            return;
        }// end function

        private function clickMeHandler(param1 = null) : void
        {
            if (!this._isLocking)
            {
                return;
            }
            var _loc_2:* = (dragSource as SkillInfo).tSkill.posType;
            var _loc_3:* = GameDefConfig.instance.getOtherSkillTypeByPosType(_loc_2);
            var _loc_4:* = ToolTipSkill.getIsFashionUnlocked(_loc_3, _loc_2);
            var _loc_5:* = ToolTipSkill.getOtherSkillPartName(_loc_3);
            MsgManager.showRollTipsMsg(_loc_5 + Language.getStringByParam(35432, _loc_4));
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            if (this._lockIcon)
            {
                this._lockIcon.dispose(param1);
                this._lockIcon = null;
            }
            if (this._stateIcon)
            {
                this._stateIcon.dispose(param1);
                this._stateIcon = null;
            }
            if (this._colorBg)
            {
                this._colorBg.dispose(param1);
                this._colorBg = null;
            }
            this._isShowColorBg = true;
            this._isLocking = false;
            this._hasLearnSkill = false;
            this._isShowUpgradeBtn = false;
            this.upgradeParam = null;
            this.callBack = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function setLockPos() : void
        {
            if (this.isDisposed)
            {
                return;
            }
            if (this._lockIcon)
            {
                this._lockIcon.x = (this.width - this._lockIcon.width) * 0.5;
                this._lockIcon.y = (this.height - this._lockIcon.height) * 0.5;
            }
            return;
        }// end function

        protected function resetStateIconPos() : void
        {
            if (isDisposed)
            {
                return;
            }
            if (this._stateIcon)
            {
                this._stateIcon.x = (this.width - this._stateIcon.width) * 0.5;
                this._stateIcon.y = (this.height - this._stateIcon.height) * 0.5;
            }
            return;
        }// end function

        public function get isShowColorBg() : Boolean
        {
            return this._isShowColorBg;
        }// end function

        public function set isShowColorBg(param1:Boolean) : void
        {
            this._isShowColorBg = param1;
            return;
        }// end function

        public function updateColorShow(param1:SkillInfo) : void
        {
            if (this.isShowColorBg && param1 && param1.tSkill != null)
            {
                this.updateColorBg(param1.tSkill.skillLevel);
            }
            else
            {
                this.updateColorBg(0);
            }
            return;
        }// end function

        protected function updateColorBg(param1:int) : void
        {
            var _loc_2:String = null;
            if (param1 >= 1 && param1 <= 4)
            {
                if (this._colorBg == null)
                {
                    this._colorBg = UIFactory.bg(1, 1, 10, 10, _middleLayer);
                }
                if (this._colorBg.parent == null)
                {
                    _middleLayer.addChild(this._colorBg);
                }
                _middleLayer.setChildIndex(this._colorBg, 0);
                _loc_2 = "ItemColorBg" + param1.toString();
                this._colorBg.resetBitmapDataAndScale9Grid(GlobalClass.getBitmapData(_loc_2), ResourceConst.getRectangle(_loc_2));
                this._colorBg.setSize(this.width - 2, this.height - 2);
            }
            else if (this._colorBg != null)
            {
                this._colorBg.dispose(true);
                this._colorBg = null;
            }
            return;
        }// end function

        public function set isShowLock(param1:Boolean) : void
        {
            this._isLocking = param1;
            if (param1)
            {
                if (this._lockIcon == null)
                {
                    this._lockIcon = UIFactory.gImageBitmap(this.lockIconStyleName, 0, 0, this, this.setLockPos);
                    this._lockIcon.x = this._paddingLeft;
                    this._lockIcon.y = this._paddingTop;
                    _topLayer.addChild(this._lockIcon);
                }
                this.bitmap.filters = [FilterConst.colorFilter2];
            }
            else
            {
                if (this._lockIcon)
                {
                    this._lockIcon.dispose();
                    this._lockIcon = null;
                }
                this.bitmap.filters = [];
            }
            return;
        }// end function

        public function set isShowUpgradeBtn(param1:Boolean) : void
        {
            return;
        }// end function

        public function set hasLearnSkill(param1:Boolean) : void
        {
            this._hasLearnSkill = param1;
            if (param1)
            {
                this.bitmap.filters = [];
                this.updateColorShow(skillInfo);
            }
            else
            {
                this.bitmap.filters = [FilterConst.colorFilter2];
                this.updateColorBg(0);
            }
            return;
        }// end function

        public function get isLocking() : Boolean
        {
            return this._isLocking;
        }// end function

        public function get hasLearnSkill() : Boolean
        {
            return this._hasLearnSkill;
        }// end function

        public function useSkillBook(event:MouseEvent) : void
        {
            if (this.callBack != null)
            {
                this.callBack.apply(null, [this.upgradeParam]);
            }
            return;
        }// end function

        public function setBtnPosition(param1:int, param2:int) : void
        {
            return;
        }// end function

        public function setState(param1:int = 0, param2:String = "otherSkillUpdateState_") : void
        {
            if (param1 > 0)
            {
                if (this._stateIcon == null)
                {
                    this._stateIcon = UIFactory.gImageBitmap("", _paddingLeft, _paddingTop, _topLayer, this.resetStateIconPos);
                }
                this._stateIcon.imgUrl = param2 + param1 + ".png";
                this.configEventListener(MouseEvent.CLICK, this.useSkillBook);
                EffectManager.glowFilterReg(this);
            }
            else
            {
                if (this._stateIcon)
                {
                    this._stateIcon.dispose();
                    this._stateIcon = null;
                    EffectManager.glowFilterUnReg(this);
                }
                this.removeEventListener(MouseEvent.CLICK, this.useSkillBook);
            }
            return;
        }// end function

    }
}
